﻿using MoetutuServer.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MoetutuServer.WebSite.Huaban
{
    class HuabanHelper
    {        /// <summary>
             /// P站判断是否合格 如果需要跳出返回true
             /// </summary>
             /// <param name="ImgID"></param>
             /// <param name="TagList"></param>
             /// <returns></returns>
        public static bool PixivJudge(string NewTag, List<string> TagList)
        {
            if (TagIdentify(TagList))
            {
                PrintLog.Log("这个图片所有标签不合格。" + NewTag);
                foreach (string line in TagList)
                {

                    Console.WriteLine(line);
                }
               return true;
            }
            string Shtml = WebHelper.HttpGet("https://pic.moetutu.com/?s=" + NewTag);
            if (Shtml == "")
            {
                Console.WriteLine("解析HTML失败");
                return true;
            }
            //检测是否发过
            List<string> TempList = HtmlHelper.GetLinkVlaueList(Shtml, "//a[@class='thumb-holder-link']");


            if (TempList.Count > 0) {

                Console.WriteLine("已经发布过，跳过");
                return true;
            }
            return false;
        }
        /// <summary>
        /// 检查哪一种后缀是真实的URL
        /// </summary>
        /// <param name="ImgUrl"></param>
        /// <returns></returns>
        public static String GetImg(String ImgUrl)
        {

            if (WebHelper.GetStatusCode(ImgUrl + ".jpg"))
                return ImgUrl + ".jpg";
            if (WebHelper.GetStatusCode(ImgUrl + ".png"))
                return ImgUrl + ".png";
            return "";
        }
        /// <summary>
        /// 识别这个画师是否增加了有意义的标签，如果是 原创 漫画这种宽泛意义的标签，这个图不能被人主动检索到，那就不收录  如果需要跳过返回true
        /// 
        /// </summary>
        /// <param name="TagList"></param>
        /// <returns></returns>
        public static bool TagIdentify(List<String> TagList)
        {
            if (TextHelper.JudgeExcludeText(TagList, StaticValue.ExcludeKey))
                return true;

            int Count = TagList.Count;
            foreach (String line in TagList)
            {
                if (StaticValue.SafeTagList.Contains(line))
                    Count--;
            }

            if (Count == 0)
                return true;
            else
                return false;
        }


        /// <summary>
        /// 判断是否需要跳出，需要跳出返回true
        /// </summary>
        /// <param name="single"></param>
        /// <returns></returns>
        public static bool JudgeQualified(HuabanStaticValue.HuabanListJson.PinsItem Single)
        {
            int Height = Single.file.height;
            int Width = Single.file.width;
            if (Height < 800 && Width < 600)
            {
                Console.WriteLine("宽{0},高{1}，太小跳过", Width, Height);
                return true;
            }
            if (Height > 4000)
            {
                Console.WriteLine("图片太长跳过");
                return true;
            }


            return false;

        }
    }
}
